package com.cps.match.xmlparser;

import com.cps.match.sdo.EnquiryResponse;
import com.cps.match.sdo.Merchant;
import com.cps.match.sdo.MerchantMatch;
import com.cps.match.sdo.Principal;
import com.cps.match.sdo.PrincipalMatch;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper;

public class EnquiryResponseParser {
	public static XStream configXtreamRequest() {
		XStream stream = new XStream(new DomDriver()) {
			@Override
			protected MapperWrapper wrapMapper(MapperWrapper next) {
				return new UpperCaseMapper(next);
			}
		};
		
		stream.alias("ns2:TerminationInquiry", EnquiryResponse.class);
		stream.aliasField("ref", EnquiryResponse.class, "reference");
		
		stream.registerConverter(new ConvertAcquirerId());
		stream.registerConverter(new ConvertMerchantMatch());
		stream.registerConverter(new ConvertPrincipleMatch());
		
		stream.addImplicitCollection(Merchant.class, "principal", Principal.class);
		stream.addImplicitCollection(MerchantMatch.class, "principalMatch", PrincipalMatch.class);

		return stream;
	}

	public static EnquiryResponse unmarshall(String xmlcontent) {
		XStream xStream = configXtreamRequest();
		return (EnquiryResponse)xStream.fromXML(xmlcontent);
	}
}

